﻿using System;
using System.Collections.Generic;
using System.IO;

namespace YaSuoCompress.Zip
{
    public class YasuoUnZip : IDisposable
    {
        internal ZipFile zip;
        public YasuoUnZip(Stream stream)
        {
            zip = new ZipFile(stream);
        }

        public void Dispose()
        {
            zip.Close();
        }

        public IEnumerable<ZipEntry> ListDirectory()
        {
            foreach (ZipEntry zipitem in zip) if (zipitem.IsDirectory) yield return zipitem;
        }

        public IEnumerable<ZipFileItem> ListFiles()
        {
            foreach (ZipEntry zipitem in zip) if (!zipitem.IsDirectory) yield return new ZipFileItem(zipitem,zip);
        }

    }
    public class ZipFileItem
    {
        public ZipFileItem(ZipEntry entry, ZipFile file)
        {
            Entry = entry;
            zip = file;
        }
        internal ZipFile zip { get; set; }
        public ZipEntry Entry { get; internal set; }
        public string Path { get { return Entry.Name; } }
        public Stream GetStream() { return zip.GetInputStream(Entry); }
    }
}
